package com.vstudy.web.annotaionTest;


import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class LoginTest {
    @Login(username = "admin", password = "123")
    public void login() {

    }

    public static void main(String[] args) throws NoSuchMethodException {
        Method loginMethod = LoginTest.class.getMethod("login");
        System.out.println(loginMethod);
        // 判断该方法上是否存在Login注解
        System.out.println(loginMethod.isAnnotationPresent(Login.class) ? "该方法有Login注解" : "该方法没有Login注解");

        // 获取该方法的所有注解信息
        Annotation[] annotations = loginMethod.getAnnotations();
        for (Annotation a : annotations) {
            if (a != null && a instanceof Login) {
                String username = ((Login) a).username();
                String password = ((Login) a).password();
                System.out.println("username: " + username);
                System.out.println("password: " + password);
            }
            System.out.println(a);
        }
    }
}
